﻿using OABLL;
using OAModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace MyOA
{
    public partial class 报销管理 : Form
    {
        public string _yuangongid = string.Empty;

        baoxiaobll bll = new baoxiaobll();  
        public 报销管理(string oa)
        {
            InitializeComponent();
            this._yuangongid = oa;
        }




        //添加申请
        private void button1_Click(object sender, EventArgs e)
        {
            
              BaoXiaoGuanli bx=new BaoXiaoGuanli(_yuangongid);

            bx.sx += new BaoXiaoGuanli.Save(bx_sx);
            bx.Show();
          
        }



        void bx_sx()
        {
            shuaxin();
        }


            //修改申请
            private void button3_Click(object sender, EventArgs e)
        {
            if (this.listView2.SelectedItems.Count > 0)
            {

                string Oa报销单号 = this.listView2.SelectedItems[0].SubItems[2].Text.Trim();

                new zcsq2(Oa报销单号, _yuangongid).Show();
            }
            else
            {
                MessageBox.Show("请选择数据");
            }


        }

        //页面加载时出现数据
        private void 报销管理_Load(object sender, EventArgs e)
        {
            List<BaoxiaoEntity> list = bll.Getyhxinxi(_yuangongid);
            for (int i = 0; i < list.Count; i++)
            {
               BaoxiaoEntity user = list[i];
                ListViewItem item = new ListViewItem();
                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                item.SubItems.Add(user.Oa报销单号);

                item.SubItems.Add(user.Oa报销内容);
                item.SubItems.Add(user.Oa金额);
                item.SubItems.Add((user.Oa报销时间.ToString()));


                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);
                //把封装好的数据添加到每一行 
                this.listView2.Items.Add(item);
            }
        }


        //删除申请
        private void button2_Click(object sender, EventArgs e)
        {
           
                if (this.listView2.SelectedItems.Count > 0)
                {

                if (MessageBox.Show("确认要删除吗?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {

                    string Oa报销单号 = this.listView2.SelectedItems[0].SubItems[2].Text.Trim();

                    if (bll.Dropshengqi(Oa报销单号))
                    {

                        foreach (ListViewItem item in this.listView2.SelectedItems)
                        {
                            this.listView2.Items.RemoveAt(item.Index);
                        }
                    }
                    else
                    {
                        MessageBox.Show("删除失败，请稍后重试！");
                    }
                }

            }else
            {
                MessageBox.Show("请选择数据");
            }
        }


        //刷新
        private void button4_Click(object sender, EventArgs e)
        {
            shuaxin();
        }

        private void shuaxin()
        {
            List<BaoxiaoEntity> list = new List<BaoxiaoEntity>();
            list = bll.Getyhxinxi(_yuangongid);
            listView2.Items.Clear();
            foreach (BaoxiaoEntity user in list)
            {
                ListViewItem item = new ListViewItem();

                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                item.SubItems.Add(user.Oa报销单号);

                item.SubItems.Add(user.Oa报销内容);
                item.SubItems.Add(user.Oa金额);
                item.SubItems.Add((user.Oa报销时间.ToString()));
                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);
                //把封装好的数据添加到每一行 
                this.listView2.Items.Add(item);

            }
        }
    }
}
